package sf.j2tree.part1;

/**
 * Created by ping on 2017-09-08.
 */
public class ParamsPassTest {

    public static void main(String[] args) {

        /***
         * 1. 方法内修改基础数据类型（数字类型或布尔类型）不会改变方法外的参数；
         */
        Integer a = 5;
        System.out.println("入栈前 a = " + a);
        calc(a);
        System.out.println("出栈后 a = " + a);
        System.out.println("***************************");
        /***
         * 2. 方法内修改对象（包含数组）状态会同步修改方法方法外的参数。
         */
        Stu tom = new Stu(30, "tom");
        System.out.println("入栈前 tom = " + tom);
        doubleScore(tom);
        System.out.println("出栈后 tom = " + tom);
        System.out.println("***************************");

        /***
         * 3. 方法不能改变对象参数的引用
         */
        System.out.println("入栈前 tom = " + tom);
        convert(tom);
        System.out.println("出栈后 tom = " + tom);
        System.out.println("***************************");


    }

    private static void calc(Integer a) {
        a = a * 3;
        System.out.println("栈内计算 a = " + a);
    }

    private static void convert(Stu tom) {
        tom = new Stu(50, "jack");
        System.out.println("栈内计算 tom = " + tom);
    }

    private static void link(String s) {
        s = s + 2;
        System.out.println("栈内计算 s = " + s);
    }




    private static void doubleScore(Stu tom) {
        tom.score = tom.score * 2;
        System.out.println("栈内计算 tom = " + tom);
    }

    private static class Stu {
        String name;
        int score;
        public Stu(int score, String name) {
            this.score = score;
            this.name = name;
        }
        @Override
        public String toString() {
            return "[ name='" + name + '\'' + ", score=" + score + ']';
        }
    }


}
